package com.wangjiyuan.giftshuo.ui.activity.classify.strategy_details.column_details.all_details;

import android.content.Context;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

import com.wangjiyuan.giftshuo.R;
import com.wangjiyuan.giftshuo.bean.classifybean.strategy.ColumnBean;
import com.wangjiyuan.giftshuo.ui.activity.classify.strategy_details.column_details.all_details.adapter.ColumnDetRecyclerAdapter;

import java.util.ArrayList;
import java.util.List;

import static com.wangjiyuan.giftshuo.R.id.recyclerView_column_details;

/**
 * 栏目 点击查看全部 的界面
 */
public class ColumnDetailsActivity extends AppCompatActivity implements ColumnDetContract.IColumnView {
    private int limit = 20;
    private int offset = 0;
    private Context mContext = this;

    private Toolbar toolbar_column_details;
    private RecyclerView mRecyclerView;
    private List<ColumnBean.DataBean.ColumnsBean> columnList=new ArrayList<>();
    private ColumnDetRecyclerAdapter columnDetAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_column_details);
        ColumnDetailsPresenter presenter = new ColumnDetailsPresenter(this);
        presenter.getColumDetailsObservable(limit, offset);
        initView();
    }

    private void initView() {
        toolbar_column_details= (Toolbar) findViewById(R.id.toolbar_column_details);
        initToolBar();

        mRecyclerView = (RecyclerView) findViewById(recyclerView_column_details);
        mRecyclerView.setHasFixedSize(true);
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(mContext, OrientationHelper.VERTICAL,false);
        columnDetAdapter=new ColumnDetRecyclerAdapter(mContext,columnList);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        mRecyclerView.setAdapter(columnDetAdapter);
    }

    private void initToolBar() {
        toolbar_column_details.setTitle("");
        setSupportActionBar(toolbar_column_details);
        ActionBar supportActionBar = getSupportActionBar();
        supportActionBar.setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case android.R.id.home:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void loadData(ColumnBean columnBean) {
        List<ColumnBean.DataBean.ColumnsBean> columns = columnBean.getData().getColumns();
        columnDetAdapter.reloadRecyclerView(columns,true);
    }
}
